package com.frank.test;

import org.junit.Test;

import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.*;

/**
 * Created by Frank on 2017/2/7.
 */
public class InterestingCode {

    /**
     * make print aaaa to bbbb
     */
    @Test
    public void planA(){
        try {
            String aaaa = "aaaa";
            Field field = String.class.getDeclaredField("value");
            field.setAccessible(true);
            char[] value = (char[]) field.get(aaaa);
            Arrays.fill(value, 'b');
        } catch (Exception e) {
        }
        System.out.println("aaaa");
    }

    @Test
    public void planB(){
        System.setOut(new PrintStream(System.out) {
            public void println(String str) {
                super.println("bbb");
            }
        });

        System.out.println("aaa");
    }
}
